/*****************************************************************************
 * plum_hal_i2c.h
 *
 * Copyright (C) 2020 Jeasonvor <1101627719@qq.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/

#ifndef __PLUM_HAL_I2C_H__
#define __PLUM_HAL_I2C_H__

/*****************************************************************************
 * Included Files
 ****************************************************************************/

/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

/*****************************************************************************
 * Public Types
 ****************************************************************************/

typedef struct {
    plum_u32 scl;
    plum_u32 sda;
} plum_hal_i2c_gpio_t;

typedef enum {
    PLUM_HAL_I2C_MODE_MASTER,
    PLUM_HAL_I2C_MODE_SLAVE,
} plum_hal_i2c_mode_t;

typedef struct {
    plum_hal_i2c_gpio_t gpio;
    plum_hal_i2c_mode_t mode;
} plum_hal_i2c_cof_t;

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
 * Public Function Prototypes
 ****************************************************************************/

/**
 * @brief:  I2C端口初始化
 *
 * @param[in]:  id  -   plum id，refer@PLUM_HAL_I2C_ID
 * @param[in]:  cof -   端口配置
 *
 * @return: 返回执行状态
 **/
plum_s32 plum_hal_i2c_init(plum_u32 id, plum_hal_i2c_cof_t *cof);

/**
 * @brief:  利用I2C端口发送数据
 *
 * @param[in]:  id      -   plum id，refer@PLUM_HAL_I2C_ID
 * @param[in]:  wData   -   待发送数据指针
 * @param[in]:  len     -   待发送数据长度
 *
 * @return: 返回执行状态
 **/
plum_s32 plum_hal_i2c_send(plum_u32 id, plum_u8 *wData, plum_u32 len);

/**
 * @brief:  利用I2C端口接收数据
 *
 * @param[in]:  id      -   plum id，refer@PLUM_HAL_I2C_ID
 * @param[out]: rData   -   待接收数据存储指针
 * @param[in]:  len     -   最大接收数据长度
 *
 * @return: 返回执行状态
 **/
plum_s32 plum_hal_i2c_recv(plum_u32 id, plum_u8 *rData, plum_u32 len);

/****************************************************************************/
#ifdef __cplusplus
}
#endif
/****************************************************************************/
#endif /* __PLUM_HAL_I2C_H__ */
/****************************************************************************/

/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
